package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.MallActivityProduct;
import com.ktgj.customer.service.IMallActivityProductService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 活动商品Controller
 * 
 * @author ruoyi
 * @date 2022-05-30
 */
@RestController
@RequestMapping("/mallActivityProduct")
public class MallActivityProductController extends BaseController
{
    @Autowired
    private IMallActivityProductService mallActivityProductService;

    /**
     * 查询活动商品列表
     */
    @PreAuthorize(hasPermi = "customer:product:list")
    @GetMapping("/list")
    public TableDataInfo list(MallActivityProduct mallActivityProduct)
    {
        startPage();
        List<MallActivityProduct> list = mallActivityProductService.selectMallActivityProductList(mallActivityProduct);
        return getDataTable(list);
    }

    /**
     * 导出活动商品列表
     */
    @PreAuthorize(hasPermi = "customer:product:export")
    @Log(title = "活动商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallActivityProduct mallActivityProduct) throws IOException
    {
        List<MallActivityProduct> list = mallActivityProductService.selectMallActivityProductList(mallActivityProduct);
        ExcelUtil<MallActivityProduct> util = new ExcelUtil<MallActivityProduct>(MallActivityProduct.class);
        util.exportExcel(response, list, "活动商品数据");
    }

    /**
     * 获取活动商品详细信息
     */
    @PreAuthorize(hasPermi = "customer:product:query")
    @GetMapping(value = "/{activityProductId}")
    public AjaxResult getInfo(@PathVariable("activityProductId") Long activityProductId)
    {
        return AjaxResult.success(mallActivityProductService.selectMallActivityProductById(activityProductId));
    }

    /**
     * 新增活动商品
     */
    @PreAuthorize(hasPermi = "customer:product:add")
    @Log(title = "活动商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallActivityProduct mallActivityProduct)
    {
        return toAjax(mallActivityProductService.insertMallActivityProduct(mallActivityProduct));
    }

    /**
     * 修改活动商品
     */
    @PreAuthorize(hasPermi = "customer:product:edit")
    @Log(title = "活动商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallActivityProduct mallActivityProduct)
    {
        return toAjax(mallActivityProductService.updateMallActivityProduct(mallActivityProduct));
    }

    /**
     * 删除活动商品
     */
    @PreAuthorize(hasPermi = "customer:product:remove")
    @Log(title = "活动商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityProductIds}")
    public AjaxResult remove(@PathVariable Long[] activityProductIds)
    {
        return toAjax(mallActivityProductService.deleteMallActivityProductByIds(activityProductIds));
    }
}
